/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-07-10
 * Time: 18:30
 */
public class test2 {
    int ans = 0;
    public int diameterOfBinaryTree(TreeNode root) {
        get(root);
        return ans;
    }

    private int get(TreeNode root) {
        if(root==null){
            return -1;
        }
        int left = get(root.left)+1;
        int right = get(root.right)+1;
        ans = Math.max(ans,right+left);
        return Math.max(right,left);
    }


    class TreeNode{
        TreeNode left;
        TreeNode right;
    }
}
